<?php require('connections/con_gl.php'); ?>
<?php
cekAkses($_SESSION[akses],"KB-1-2");
mysql_select_db($database_con_gl, $con_gl);
$query_klasbank = "SELECT gl_klas.kd, gl_klas.klasifikasi FROM gl_klas WHERE gl_klas.tipe=2 ORDER BY gl_klas.kd, gl_klas.klasifikasi";
$klasbank = mysql_query($query_klasbank, $con_gl) or die(mysql_error());
$row_klasbank = mysql_fetch_assoc($klasbank);
$totalRows_klasbank = mysql_num_rows($klasbank);

$colname_edgetref = "-1";
if (isset($_GET['noreferensi'])) {
  $colname_edgetref = (get_magic_quotes_gpc()) ? $_GET['noreferensi'] : addslashes($_GET['noreferensi']);
}
mysql_select_db($database_con_gl, $con_gl);
$query_edgetref = sprintf("SELECT no_ref, tgl, keterangan FROM gl_rtrans WHERE no_ref = '%s'", $colname_edgetref);
$edgetref = mysql_query($query_edgetref, $con_gl) or die(mysql_error());
$row_edgetref = mysql_fetch_assoc($edgetref);
$totalRows_edgetref = mysql_num_rows($edgetref);

mysql_select_db($database_con_gl, $con_gl);
$query_getdtrans = "SELECT no_ref, total, akun, gl_trans.id FROM gl_trans WHERE no_ref='$_GET[noreferensi]' AND pos='D'";
$getdtrans = mysql_query($query_getdtrans, $con_gl) or die(mysql_error());
$row_getdtrans = mysql_fetch_assoc($getdtrans);
$totalRows_getdtrans = mysql_num_rows($getdtrans);

mysql_select_db($database_con_gl, $con_gl);
$query_getktrans = "SELECT id, no_ref, total, akun FROM gl_trans where no_ref='$_GET[noreferensi]' AND pos='K'";
$getktrans = mysql_query($query_getktrans, $con_gl) or die(mysql_error());
$row_getktrans = mysql_fetch_assoc($getktrans);
$totalRows_getktrans = mysql_num_rows($getktrans);
// ---
mysql_select_db($database_con_gl, $con_gl);
$query_gudang = "SELECT id, gudang FROM gl_gudang";
if(!strstr($_SESSION[akses],'A-1-4')) {
	$query_gudang .= " where id='$_SESSION[lokasi]'";
}
$query_gudang .=" ORDER BY gudang ASC";
$gudang = mysql_query($query_gudang, $con_gl) or die(mysql_error());
$row_gudang = mysql_fetch_assoc($gudang);
$totalRows_gudang = mysql_num_rows($gudang);
?>
<script type="text/javascript">
$(document).ready(function() {

	$().ajaxStart(function() {
		$('#loading').show();
		$('#result').hide();
	}).ajaxStop(function() {
		$('#loading').hide();
		$('#result').fadeIn('slow');
	});

	$('#edit').submit(function() {
		$.ajax({
			type: 'POST',
			url: $(this).attr('action'),
			data: $(this).serialize(),
			success: function(data) {
				$('#result').html(data);
			}
		})
		return false;
	});
  $('#result').click(function(){
  $(this).hide();
  });
})
</script>
<link href="js/ui.datepicker.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="js/ui.datepicker.js"></script>
<script type="text/javascript">
<!--
$(function()
      {
        $('.calendar').datepicker({
            appendText : "yyyy/mm/dd",
            dateFormat : 'yy/mm/dd'
          });
      });
</script>
<script type="text/javascript" src="js/ajax_data.js"></script>
<div id="loading" style="display:none;"><img src="images/loading.gif" alt="loading..." /></div>
<div id="result" style="display:none;"></div>
<h1>Edit Transfer Kas</h1>
<form action="proses/transferkas.php?act=edit" method="POST" name="edit" id="edit">
  <table width="95%" border="0" align="center" cellpadding="5" cellspacing="0" class="datatable">
    <tr valign="top">
      <td width="17%" align="right" valign="top" bgcolor="#FFFFFF">Ke (Debet) *: </td>
      <td width="33%" bgcolor="#FFFFFF"><label>
        <select name="ke" id="ke">
          <?php
do {  
?>
          <?php
mysql_select_db($database_con_gl, $con_gl);
$query_rekbank = "SELECT id, akun FROM gl_akun WHERE klasifikasi = '$row_klasbank[kd]' order by id,akun";
$rekbank = mysql_query($query_rekbank, $con_gl) or die(mysql_error());
$row_rekbank = mysql_fetch_assoc($rekbank);
$totalRows_rekbank = mysql_num_rows($rekbank);
?>
          <option value="" style="background:#DDDDDD;font-weight:bold;"><?php echo $row_klasbank['klasifikasi']?></option>
          <?php do { ?>
          <option value="<?php echo $row_rekbank['id']; ?>-<?php echo $row_rekbank['akun']; ?>" <?php if($row_rekbank['id'] == $row_getdtrans['akun']) { ?>selected="selected"<?php } ?>><?php echo $row_rekbank['id']; ?> - <?php echo $row_rekbank['akun']; ?></option>
          <?php
} while ($row_rekbank = mysql_fetch_assoc($rekbank)); ?>
          <?php
} while ($row_klasbank = mysql_fetch_assoc($klasbank));
  $rows = mysql_num_rows($klasbank);
  if($rows > 0) {
      mysql_data_seek($klasbank, 0);
	  $row_klasbank = mysql_fetch_assoc($klasbank);
  }
?>
        </select>
        <input name="id_d" type="hidden" id="id_d" value="<?php echo $row_getktrans['id']; ?>" />
      </label></td>
      <td width="12%" align="right" valign="top" bgcolor="#FFFFFF">Dari (Kredit) *:</td>
      <td width="39%" bgcolor="#FFFFFF"><label>
        <select name="dari" id="dari">
          <?php
do {  
?>
          <?php
mysql_select_db($database_con_gl, $con_gl);
$query_rekbank = "SELECT id, akun FROM gl_akun WHERE klasifikasi = '$row_klasbank[kd]' order by id,akun";
$rekbank = mysql_query($query_rekbank, $con_gl) or die(mysql_error());
$row_rekbank = mysql_fetch_assoc($rekbank);
$totalRows_rekbank = mysql_num_rows($rekbank);
?>
          <option value="" style="background:#DDDDDD;font-weight:bold;"><?php echo $row_klasbank['klasifikasi']?></option>
          <?php do { ?>
          <option value="<?php echo $row_rekbank['id']; ?>-<?php echo $row_rekbank['akun']; ?>" <?php if($row_rekbank['id'] == $row_getktrans['akun']) { ?>selected="selected"<?php } ?>><?php echo $row_rekbank['id']; ?> - <?php echo $row_rekbank['akun']; ?></option>
          <?php
} while ($row_rekbank = mysql_fetch_assoc($rekbank)); ?>
          <?php
} while ($row_klasbank = mysql_fetch_assoc($klasbank));
  $rows = mysql_num_rows($klasbank);
  if($rows > 0) {
      mysql_data_seek($klasbank, 0);
	  $row_klasbank = mysql_fetch_assoc($klasbank);
  }
?>
        </select>
        <input name="id_k" type="hidden" id="id_k" value="<?php echo $row_getdtrans['id']; ?>" />
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">No Referensi *: </td>
      <td bgcolor="#FFFFFF"><div id="refDiv"><label>
        <input name="noreferensi" type="text" id="noreferensi" value="<?php echo $row_edgetref['no_ref']; ?>" size="20" maxlength="20" onchange="cekReferensi(this.value);" onFocus="this.blur();"/>
      </label></div></td>
      <td align="right" valign="top" bgcolor="#FFFFFF">Lokasi Kantor *:</td>
      <td bgcolor="#FFFFFF"><label>
        <select name="gudang" id="gudang">
          <?php
do {  
?>
          <option value="<?php echo $row_gudang['id']?>" <?php if($row_gudang['id']==$row_edit['gudang']) { ?>selected="selected"<?php } ?>><?php echo $row_gudang['gudang']?></option>
          <?php
} while ($row_gudang = mysql_fetch_assoc($gudang));
  $rows = mysql_num_rows($gudang);
  if($rows > 0) {
      mysql_data_seek($gudang, 0);
	  $row_gudang = mysql_fetch_assoc($gudang);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">Tanggal *: </td>
      <td bgcolor="#FFFFFF"><label>
        <input name="tanggal" type="text" class="calendar" id="tanggal" value="<?php echo $row_edgetref['tgl']; ?>" size="20" maxlength="15"/>
      </label></td>
      <td align="right" bgcolor="#FFFFFF">Total :</td>
      <td bgcolor="#FFFFFF"><label>
        <input name="total" type="text" id="total" value="<?php echo $row_getdtrans['total']; ?>" size="20" maxlength="10" />
      </label></td>
    </tr>
    <tr>
      <td align="right" valign="top" bgcolor="#FFFFFF">Keterangan : </td>
      <td colspan="3" bgcolor="#FFFFFF"><label>
        <textarea name="keterangan" cols="58" rows="4" id="keterangan"><?php echo $row_edgetref['keterangan']; ?></textarea>
      </label></td>
    </tr>
    <tr>
      <td align="left" valign="top" bgcolor="#FFFFFF"><em>*Harus diisi</em></td>
      <td align="left" bgcolor="#FFFFFF"><label>
        <input name="Save" type="submit" id="Save" value="Simpan" />
        </label>
          <label>
          <input type="button" name="Button" value="Batal" onClick="javascript:history.go(-1);">
        </label></td>
      <td bgcolor="#FFFFFF">&nbsp;</td>
      <td bgcolor="#FFFFFF">&nbsp;</td>
    </tr>
  </table>
  <input name="jenis" type="hidden" id="jenis" value="2">
</form>
